package frame.base;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.TreeSet;

/**
 * frame框架的menu
 */
public class Menu implements Comparable<Menu>{
    private Integer id;
    private Integer pid;
    private String name;
    private String icon;
    private String url;
    // 该字段只需要用于后台排序
    @JSONField(serialize = false)
    private Integer sorting;
    private TreeSet<Menu> sub;

    public Integer getId() {
        return id;
    }

    public Menu setId(Integer id) {
        this.id = id;
        return this;
    }

    public Integer getPid() {
        return pid;
    }

    public Menu setPid(Integer pid) {
        this.pid = pid;
        return this;
    }

    public String getName() {
        return name;
    }

    public Menu setName(String name) {
        this.name = name;
        return this;
    }

    public String getIcon() {
        return icon;
    }

    public Menu setIcon(String icon) {
        this.icon = icon;
        return this;
    }

    public String getUrl() {
        return url;
    }

    public Menu setUrl(String url) {
        this.url = url;
        return this;
    }

    public Integer getSorting() {
        return sorting;
    }

    public Menu setSorting(Integer sorting) {
        this.sorting = sorting;
        return this;
    }

    public TreeSet<Menu> getSub() {
        return sub;
    }

    public Menu setSub(TreeSet<Menu> sub) {
        this.sub = sub;
        return this;
    }

    public Menu addSub(Menu menu) {
        if (sub == null) {
            sub = new TreeSet<>();
        }
        sub.add(menu);
        return this;
    }

    @Override
    public int compareTo(Menu o) {
        if (o == null) return 0;
        return this.sorting.compareTo(o.sorting);
    }
}
